package com.iuie.ns.system.vo.user;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.GenericGenerator;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.iuie.ns.system.vo.role.SysRoleVO;

/**
 * 
 * @description 系统用户信息
 * @author lj
 * @createTime 2016年8月21日 上午11:31:54
 */
@Table(name="SYS_USER")
@Entity
public class SysUserVO {
	/** 用户姓名 */
	@Column(name="USER_NAME")
	private String userName;
	
	/** 用户登录id */
	@Column(name="USER_ID")
	@Id
	@GeneratedValue(generator = "id_generator")    
	@GenericGenerator(name = "id_generator", strategy = "assigned")  
	private String userId;
	
	/** 用户邮箱 */
	@Column(name="USER_EMAIL")
	private String userEmail;
	
	/** 用户手机号 */
	@Column(name="USER_PHONE",unique=true)
	private String userPhone;
	
	/** 密码 */
	@Column(name="USER_PWD")
	private String userPwd;
	
	/** 用户状态 */
	@Column(name="USER_STATE")
	private Integer userState;
	
	/** 身份证号 */
	@Column(name="USER_IDCARD",unique=true)
	private String userIdcard;
	
	/** 插入这条用户信息的用户id */
	@Column(name="INSERT_USER_ID")
	private String insertUserId;
	
	/** 新增用户信息的时间 */
	@JsonFormat(pattern="yyyy-MM-dd HH:mm:ss")
	@Column(name="CREATE_TIME")
	private Date createTime;

	/** 用户头像 */
	private String avatar;
	
	@ManyToMany(mappedBy="users")
	private Set<SysRoleVO> roles = new HashSet<>();
	
	/** 最近一次登录的角色*/
	@OneToOne(cascade=CascadeType.ALL,fetch=FetchType.EAGER,targetEntity=SysRoleVO.class)
	@JoinColumn(name="last_login_role")//指定一个外键，也可以不指定。
	private SysRoleVO currentRole;
	
	@Transient
	private String insertUserName;
	
	/**
	 * 免密码登录的token
	 */
	@Column(name="LOGIN_TOKEN")
	private String loginToken;

	/**
	 * @return {@link #userName}
	 */
	public String getUserName() {
		return userName;
	}

	/**
	 * @param {@link #userName}
	 */
	public void setUserName(String userName) {
		this.userName = userName;
	}

	/**
	 * @return {@link #userId}
	 */
	public String getUserId() {
		return userId;
	}

	/**
	 * @param {@link #userId}
	 */
	public void setUserId(String userId) {
		this.userId = userId;
	}

	/**
	 * @return {@link #userEmail}
	 */
	public String getUserEmail() {
		return userEmail;
	}

	/**
	 * @param {@link #userEmail}
	 */
	public void setUserEmail(String userEmail) {
		this.userEmail = userEmail;
	}

	/**
	 * @return {@link #userPhone}
	 */
	public String getUserPhone() {
		return userPhone;
	}

	/**
	 * @param {@link #userPhone}
	 */
	public void setUserPhone(String userPhone) {
		this.userPhone = userPhone;
	}

	/**
	 * @return {@link #userPwd}
	 */
	public String getUserPwd() {
		return userPwd;
	}

	/**
	 * @param {@link #userPwd}
	 */
	public void setUserPwd(String userPwd) {
		this.userPwd = userPwd;
	}

	/**
	 * @return {@link #userState}
	 */
	public Integer getUserState() {
		return userState;
	}

	/**
	 * @param {@link #userState}
	 */
	public void setUserState(Integer userState) {
		this.userState = userState;
	}

	/**
	 * @return {@link #userIdcard}
	 */
	public String getUserIdcard() {
		return userIdcard;
	}

	/**
	 * @param {@link #userIdcard}
	 */
	public void setUserIdcard(String userIdcard) {
		this.userIdcard = userIdcard;
	}

	/**
	 * @return {@link #insertUserId}
	 */
	public String getInsertUserId() {
		return insertUserId;
	}

	/**
	 * @param {@link #insertUserId}
	 */
	public void setInsertUserId(String insertUserId) {
		this.insertUserId = insertUserId;
	}

	/**
	 * @return {@link #createTime}
	 */
	public Date getCreateTime() {
		return createTime;
	}

	/**
	 * @param {@link #createTime}
	 */
	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	/**
	 * @return the avatar
	 */
	public String getAvatar() {
		return avatar;
	}

	/**
	 * @param avatar the avatar to set
	 */
	public void setAvatar(String avatar) {
		this.avatar = avatar;
	}

	/**
	 * @return the roles
	 */
	public Set<SysRoleVO> getRoles() {
		return roles;
	}

	/**
	 * @param roles the roles to set
	 */
	public void setRoles(Set<SysRoleVO> roles) {
		this.roles = roles;
	}

	public SysRoleVO getCurrentRole() {
		return currentRole;
	}
	public void setCurrentRole(SysRoleVO currentRole) {
		this.currentRole = currentRole;
	}
	public String getInsertUserName() {
		return insertUserName;
	}
	public void setInsertUserName(String insertUserName) {
		this.insertUserName = insertUserName;
	}
	
	public String getLoginToken() {
		return loginToken;
	}

	public void setLoginToken(String loginToken) {
		this.loginToken = loginToken;
	}

	@Override
	public String toString() {
		return "SysUserVO [userName=" + userName + ", userId=" + userId
				+ ", userEmail=" + userEmail + ", userPhone=" + userPhone
				+ ", userPwd=" + userPwd + ", userState=" + userState
				+ ", userIdcard=" + userIdcard + ", insertUserId="
				+ insertUserId + ", createTime=" + createTime + ", avatar="
				+ avatar + ", roles=" + roles + ", currentRole=" + currentRole
				+ ", insertUserName=" + insertUserName + ", loginToken="
				+ loginToken + "]";
	}
    
}
